package com.restaurant.application.indexes.accumulategoodslist.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;
import com.restaurant.application.accumulategoods.support.GoodsData;
import com.restaurant.application.goodscategory.support.CategoryData;
import com.restaurant.application.shop.support.ShopVo;

import java.util.List;
import java.util.stream.Collectors;

public class MiniAccumulateShopPage implements PickableBean {

    public static final String FN_GOODS = "goods";
    public static final String FN_LISTS = "lists";
    public static final String FN_TYPES = "types";
    public static final String FN_ACCUMULATEPOINTS = "accumulatePoints";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
             FN_GOODS,
             FN_LISTS,
             FN_TYPES,
             FN_ACCUMULATEPOINTS);

    private List<GoodsData> goods;
    private List<ShopVo> lists;
    private List<CategoryData> types;
    private Integer accumulatePoints;

    public MiniAccumulateShopPage(List<GoodsData> goods, List<ShopVo> lists, List<CategoryData> types, Integer accumulatePoints) {
        setGoods(goods);
        setLists(lists);
        setTypes(types);
        setAccumulatePoints(accumulatePoints);
    }

    public MiniAccumulateShopPage() {
    }

    public MiniAccumulateShopPage duplicate() {
        MiniAccumulateShopPage result = new MiniAccumulateShopPage();
        result.goods = this.goods == null ? null : this.goods.stream().map(e1->e1 == null ? null : e1.duplicate()).collect(Collectors.toList());
        result.lists = this.lists == null ? null : this.lists.stream().map(e2->e2 == null ? null : e2.duplicate()).collect(Collectors.toList());
        result.types = this.types == null ? null : this.types.stream().map(e3->e3 == null ? null : e3.duplicate()).collect(Collectors.toList());
        result.accumulatePoints = this.accumulatePoints;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public List<GoodsData> getGoods() {
        if( goods == null) {
            goods = Lists.newArrayList();
        }
        return goods;
    }

    public void  setGoods(List<GoodsData> value) {
        this.goods = value;
    }

    public MiniAccumulateShopPage withGoods(List<GoodsData> value) {
        setGoods(value);
        return this;
    }

    public MiniAccumulateShopPage withGoods(List<GoodsData> value, List<GoodsData> defaultValue) {
        setGoods(value == null ? defaultValue : value);
        return this;
    }

    public MiniAccumulateShopPage addGoods(GoodsData value) {
        if(goods == null) {
            goods = Lists.newArrayList();
        }
        this.goods.add(value);
        return this;
    }

    public List<ShopVo> getLists() {
        if( lists == null) {
            lists = Lists.newArrayList();
        }
        return lists;
    }

    public void  setLists(List<ShopVo> value) {
        this.lists = value;
    }

    public MiniAccumulateShopPage withLists(List<ShopVo> value) {
        setLists(value);
        return this;
    }

    public MiniAccumulateShopPage withLists(List<ShopVo> value, List<ShopVo> defaultValue) {
        setLists(value == null ? defaultValue : value);
        return this;
    }

    public MiniAccumulateShopPage addLists(ShopVo value) {
        if(lists == null) {
            lists = Lists.newArrayList();
        }
        this.lists.add(value);
        return this;
    }

    public List<CategoryData> getTypes() {
        if( types == null) {
            types = Lists.newArrayList();
        }
        return types;
    }

    public void  setTypes(List<CategoryData> value) {
        this.types = value;
    }

    public MiniAccumulateShopPage withTypes(List<CategoryData> value) {
        setTypes(value);
        return this;
    }

    public MiniAccumulateShopPage withTypes(List<CategoryData> value, List<CategoryData> defaultValue) {
        setTypes(value == null ? defaultValue : value);
        return this;
    }

    public MiniAccumulateShopPage addTypes(CategoryData value) {
        if(types == null) {
            types = Lists.newArrayList();
        }
        this.types.add(value);
        return this;
    }

    public Integer getAccumulatePoints() {
        return accumulatePoints;
    }

    public void  setAccumulatePoints(Integer value) {
        this.accumulatePoints = value;
    }

    public MiniAccumulateShopPage withAccumulatePoints(Integer value) {
        setAccumulatePoints(value);
        return this;
    }

    public MiniAccumulateShopPage withAccumulatePoints(Integer value, Integer defaultValue) {
        setAccumulatePoints(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch(name) {
        case "goods": return getGoods();
        case "lists": return getLists();
        case "types": return getTypes();
        case "accumulatePoints": return getAccumulatePoints();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if(!(o instanceof MiniAccumulateShopPage)) return false;
        return signature().equals(((MiniAccumulateShopPage)o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean MiniAccumulateShopPage has no signature defined, no hash code or equals possible.");
    }
}
